package com.sec.android.app.myfiles.util.region;

import android.content.Context;

import com.sec.android.app.myfiles.util.chain.Chain;


/**
 * NOT PUBLIC
 * AbsRegionImp class shouldn't be used outside of region package
 */
abstract class AbsRegionImp implements Chain<AbsRegionImp> {
    private AbsRegionImp mNext = null;

    protected abstract String getRegionName();

    protected abstract String getRegionLanguage();

    public final String getFolderDescription(Context context, String path) {
        String ret = null;
        if (isSupportRegion(context)) {
            ret = getFolderDescriptionImp(context, path);
        } else {
            if (mNext != null) {
                ret = mNext.getFolderDescription(context, path);
            }
        }
        return ret;
    }

    @Override
    public void setNext(AbsRegionImp next) {
        mNext = next;
    }

    protected boolean isSupportRegion(Context context) {
        String supportRegionName = getRegionName();
        String supportRegionLanguage = getRegionLanguage();
        if (supportRegionName == null || supportRegionLanguage == null) { //Common will return null
            return true;
        }

        String curRegionName = context.getResources().getConfiguration().locale.getCountry();
        String curRegionLanguage = context.getResources().getConfiguration().locale.getLanguage();
        return (supportRegionName.equals(curRegionName) && supportRegionLanguage.equals(curRegionLanguage));
    }


    protected abstract String getFolderDescriptionImp(Context context, String path);
}
